Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
shell-escape
Advanced tools
Escape and stringify an array of arguments to be executed on the shell
The shell-escape npm package is used to escape and sanitize strings for use in shell commands. This is particularly useful to prevent shell injection attacks and ensure that shell commands are executed safely.
Basic String Escaping
This feature allows you to escape a basic string to be safely used in a shell command. The example demonstrates escaping a simple echo command.
const shellEscape = require('shell-escape');
const command = shellEscape(['echo', 'Hello World']);
console.log(command); // Output: echo 'Hello World'
Escaping Arguments with Special Characters
This feature shows how to escape arguments that contain special characters. The example demonstrates escaping a string with an ampersand.
const shellEscape = require('shell-escape');
const command = shellEscape(['echo', 'Hello & World']);
console.log(command); // Output: echo 'Hello & World'
Escaping File Paths
This feature allows you to escape file paths that may contain spaces or other special characters. The example demonstrates escaping a file path with spaces.
const shellEscape = require('shell-escape');
const filePath = '/path/to/some file.txt';
const command = shellEscape(['cat', filePath]);
console.log(command); // Output: cat '/path/to/some file.txt'
The shell-quote package provides similar functionality to shell-escape, allowing you to escape and quote strings for use in shell commands. It also offers additional features like parsing shell commands into arguments. Compared to shell-escape, shell-quote provides more comprehensive parsing and quoting capabilities.
The shescape package is another alternative for escaping strings for shell commands. It focuses on providing a simple and effective way to escape strings, similar to shell-escape. However, it may not have as many features as shell-quote.
Escape and stringify an array of arguments to be executed on the shell
npm install shell-escape
var shellescape = require('shell-escape');
var args = ['curl', '-v', '-H', 'Location;', '-H', 'User-Agent: dave#10', 'http://www.daveeddy.com/?name=dave&age=24'];
var escaped = shellescape(args);
console.log(escaped);
yields
curl -v -H 'Location;' -H 'User-Agent: dave#10' 'http://www.daveeddy.com/?name=dave&age=24'
A command suitable for being executed by the shell
var shellescape = require('shell-escape');
var args = ['echo', 'hello!', 'how are you doing $USER', '"double"', "'single'"];
var escaped = shellescape(args);
console.log(escaped);
yields
echo 'hello!' 'how are you doing $USER' '"double"' \''single'\'
and when run on the shell
$ echo 'hello!' 'how are you doing $USER' '"double"' \''single'\'
hello! how are you doing $USER "double" 'single'
MIT
FAQs
Escape and stringify an array of arguments to be executed on the shell
The npm package shell-escape receives a total of 238,689 weekly downloads. As such, shell-escape popularity was classified as popular.
We found that shell-escape demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.